import 'package:flutter/material.dart';

//引入四个组件
import 'package:flutter_app/pages/components/Contact.dart';
import 'package:flutter_app/pages/components/Home.dart';
import 'package:flutter_app/pages/components/Profile.dart';
import 'package:flutter_app/pages/components/Dynamic.dart';
class Tap extends StatefulWidget {
  Tap({Key key}) : super(key: key);

  @override
  _TapState createState() => _TapState();
}

class _TapState extends State<Tap> {
  int currentIndex ;
  //默认图片的颜色
  String homePath = "images/common/drawable-mdpi/nav_btn_home_default.png";
  String contactPath = "images/common/drawable-mdpi/nav_btn_linkman_default.png";
  String dynamicPath = "images/common/drawable-mdpi/nav_btn_dynamic_default.png";
  String profilePath = "images/common/drawable-mdpi/nav_btn_my_default.png";
  //切换navagation
  List navigation = [
    Home(),
    Contact(),
    Dynamic(),
    Profile()
  ];
  //初始化
  @override
  void initState() {
    super.initState();
    this.currentIndex = 0;
    this.handIconPath(this.currentIndex);
  }
  //加载图标函数
  void handIconPath(int index){
    //切换颜色
    switch (index) {
      case 0:
        setState(() {
          this.homePath = "images/common/drawable-mdpi/nav_btn_home_selected.png";
          this.contactPath = "images/common/drawable-mdpi/nav_btn_linkman_default.png";
          this.dynamicPath = "images/common/drawable-mdpi/nav_btn_dynamic_default.png";
          this.profilePath = "images/common/drawable-mdpi/nav_btn_my_default.png";
        });
        break;
      case 1:
        setState(() {
          this.homePath = "images/common/drawable-mdpi/nav_btn_home_default.png";
          this.contactPath = "images/common/drawable-mdpi/nav_btn_linkman_selected.png";
          this.dynamicPath = "images/common/drawable-mdpi/nav_btn_dynamic_default.png";
          this.profilePath = "images/common/drawable-mdpi/nav_btn_my_default.png";
        });
        break;
      case 2:
        setState(() {
          this.homePath = "images/common/drawable-mdpi/nav_btn_home_default.png";
          this.contactPath = "images/common/drawable-mdpi/nav_btn_linkman_default.png";
          this.dynamicPath = "images/common/drawable-mdpi/nav_btn_dynamic_selected.png";
          this.profilePath = "images/common/drawable-mdpi/nav_btn_my_default.png";
        });
        break;
      case 3:
        setState(() {
          this.homePath = "images/common/drawable-mdpi/nav_btn_home_default.png";
          this.contactPath = "images/common/drawable-mdpi/nav_btn_linkman_default.png";
          this.dynamicPath = "images/common/drawable-mdpi/nav_btn_dynamic_default.png";
          this.profilePath = "images/common/drawable-mdpi/nav_btn_my_selected.png";
        });
        break;
      default:
    }
  }
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      // appBar: AppBar(
      //   title: Text("叮咚"),
      // ),
      body: this.navigation[this.currentIndex],
      bottomNavigationBar: BottomNavigationBar(
        currentIndex: this.currentIndex,
        onTap: (int index) {
          setState(() {
            this.currentIndex = index;
            this.handIconPath(this.currentIndex);
          });
        },
        items: [
          BottomNavigationBarItem(icon: Image.asset(this.homePath), title: Text('通话')),
          BottomNavigationBarItem(icon: Image.asset(this.contactPath), title: Text('联系人')),
          BottomNavigationBarItem(icon: Image.asset(this.dynamicPath), title: Text('动态')),
          BottomNavigationBarItem(icon: Image.asset(this.profilePath),title: Text('我的',),),
        ],
        fixedColor: Colors.red, //选中颜色
        type: BottomNavigationBarType.fixed, //类型
      ),
    );
  }
}
